import request from '../utils/request';


// 获取公告列表
export const getNoticeList = query => {
    return request({
        url: '/notice/list',
        method: 'get',
        params: query
    });
};

// 修改公告信息
export const modifyNotice = form => {
    return request({
        url: '/notice',
        method: 'put',
        data: form
    });
};

// 新增公告
export const addNotice = form => {
    return request({
        url: '/notice',
        method: 'post',
        data: form
    });
};

// 删除公告
export const deleteNotice = param => {
    return request({
        url: '/notice/' + param,
        method: 'delete'
    });
};


// 获取微信用户信息列表
export const getUserList = query => {
    return request({
        url: '/wx-user/list/',
        method: 'get',
        params: query
    });
};

// 获取微信用户详情信息
export const getUserDetail = param => {
    return request({
        url: '/wx-user/' + param,
        method: 'get'
    });
};


// 禁用用户
export const disableUser = param => {
    return request({
        url: '/wx-user/' + param,
        method: 'put'
    });
};

// 获取实名认证信息列表
export const getUserInfoList = query => {
    return request({
        url: '/audit/userInfo/',
        method: 'get',
        params: query
    });
};

// 审核实名认证信息
export const auditUserInfo = (id, result) => {
    return request({
        url: '/audit/userInfo/' + id + '/' + result,
        method: 'put'
    });
};

// 获取实名认证信息列表
export const getCollectorList = query => {
    return request({
        url: '/audit/collector/',
        method: 'get',
        params: query
    });
};

// 审核实名认证信息
export const auditCollector = (id, result) => {
    return request({
        url: '/audit/collector/' + id + '/' + result,
        method: 'put'
    });
};

// 获取回收物类别信息列表
export const getCategoryList = query => {
    return request({
        url: '/type/category/',
        method: 'get',
        params: query
    });
};

// 添加回收物类别
export const addCategory = (form) => {
    return request({
        url: '/type/category',
        method: 'post',
        params: form
    });
};

// 获取回收物信息列表
export const getItemList = query => {
    return request({
        url: '/type/item/',
        method: 'get',
        params: query
    });
};

// 添加回收物
export const addItem = (form) => {
    return request({
        url: '/type/item',
        method: 'post',
        data: form
    });
};

// 获取回收物信息列表
export const allItem = () => {
    return request({
        url: '/type/category/all',
        method: 'get'
    });
};


// 获取订单信息列表
export const getOrderList = query => {
    return request({
        url: '/order',
        method: 'get',
        params: query
    });
};

// 获取订单详情信息
export const getOrderDetail = param => {
    return request({
        url: '/order/detail/' + param,
        method: 'get',
    });
};


// 导出订单Excel
export const getOrderExcel = param => {
    return request({
        url: '/order/excel/',
        method: 'get',
        params: param,
        responseType: 'blob',
        headers: {
            'Content-Type': 'application/x-download'
        }
    });
};

// 获取最近七天的订单总数，订单金额，废品总重量
export const getOrderSevenData = () => {
    return request({
        url: '/data/order-seven',
        method: 'get'
    });
};

// 获取各类回收物的重量占比
export const getCategoryWeight = (param) => {
    return request({
        url: '/data/category-weight',
        method: 'get',
        params: param
    });
};

// 删除供应商
export const deleteSupplier = param => {
    return request({
        url: '/medicine/supplier/?id='+param,
        method: 'delete'
    });
};

// 获取采购信息列表
export const getBillList = query => {
    return request({
        url: '/medicine/bill/list/',
        method: 'get',
        params: query
    });
};

// 获取采购信息详情
export const getBillDetail = param => {
    return request({
        url: '/medicine/bill/'+param,
        method: 'get',
    });
};

// 采购登记
export const addBill = form => {
    return request({
        url: '/medicine/bill/particular',
        method: 'post',
        data: form
    });
};


// 获取所有医生信息列表
export const allDoctor = () => {
    return request({
        url: '/medicine/doctor/all'
    })
}

// 获取所有供应商信息列表
export const allSupplier = () => {
    return request({
        url: '/medicine/supplier/all'
    })
}

// 获取所有供应商信息列表
export const allMedicine = () => {
    return request({
        url: '/medicine/medicine/all'
    })
};

// 销售登记
export const addPatientBill = form => {
    return request({
        url: '/medicine/patient-bill/particular',
        method: 'post',
        data: form
    });
};

// 获取销售信息列表
export const getPatientBillList = query => {
    return request({
        url: '/medicine/patient-bill/list/',
        method: 'get',
        params: query
    });
};

// 获取销售信息详情
export const getPatientBillDetail = param => {
    return request({
        url: '/medicine/patient-bill/message/'+param,
        method: 'get',
    });
};

// 新增账号
export const addAdmin = form => {
    return request({
        url: '/medicine/administrator',
        method: 'post',
        data: form
    });
};

// 修改密码
export const modifyAdmin = form => {
    return request({
        url: '/user/password',
        method: 'put',
        data: form
    });
};

// 获取账号列表
export const getAdminList = query => {
    console.log(query);
    return request({
        url: '/medicine/administrator/list/',
        method: 'get',
        params: query
    });
};

// 删除账号
export const deleteAdmin = param => {
    return request({
        url: '/medicine/administrator/?id=' + param,
        method: 'delete'
    });
};

// 登录
export const loginAdmin = form => {
    return request({
        url: '/user/login',
        method: 'post',
        data: form
    });
};

// 获取基本数据
export const getBaseData = () => {
    return request({
        url: '/medicine/data/base',
        method: 'get'
    });
};

// 获取柱状图数据
export const getBarData = () => {
    return request({
        url: '/medicine/data/bar',
        method: 'get'
    });
};

export const yuanToFen = (price) => {
  if (!price) return 0;
  return price * 100;
};

export const fenToYuan = (price) => {
    if (!price) return 0;
    return price/100.00;
};

export const kgToG = (weight) => {
    if (!weight) return 0;
    return weight * 1000;
};

export const gToKg = (weight) => {
    if (!weight) return 0;
    return weight / 1000.000;
};

export const dateConvert = (date, begin) => {
    if (!date) return "";
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    if (begin) {
        return year + '/' + month + '/' + day + " 00:00:00";
    } else {
        return year + '/' + month + '/' + day + " 23:59:59";
    }
};